package com.hnmqet.demo02.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hnmqet.demo02.dao.OrderTblMapper;
import com.hnmqet.demo02.entity.OrderTbl;
import com.hnmqet.demo02.service.OrderTblService;
import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author td
 * @since 2020-01-07
 */
@Service
@Slf4j
public class OrderTblServiceImpl extends ServiceImpl<OrderTblMapper, OrderTbl> implements OrderTblService {


    @Autowired
    OrderTblMapper orderTblMapper;

    @Override
    @Transactional
    public void test(String userId, String code, String count) {
        log.info("Assign Service Begin ... xid: " + RootContext.getXID() + "\n");
        // 创建订单
        OrderTbl orderTbl = new OrderTbl();
        orderTbl.setUserId(userId);
        orderTbl.setCommodityCode(code);
        orderTbl.setCount(Integer.parseInt(count));
        int insert = orderTblMapper.insert(orderTbl);
        System.out.println(insert + orderTbl.toString());
    }

    @Override
    public void batchUpdate() {
        OrderTbl orderTbl = orderTblMapper.selectById(24917);
        orderTbl.setUserId("ewewew");
        int i = orderTblMapper.updateById(orderTbl);
        log.info("Assign Service Begin ... xid: " + RootContext.getXID() + "\n");

    }
}
